﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data;
using KPIS.DBM;
using KPIS.GERP.GBMS.DAL;
using KPIS.GERP.GBMS.MODEL;
using KPIS.GERP.GBMS.DALFactory;
using KPIS.GERP.GBMS.IBLL;
using System.Globalization;

namespace KPIS.GERP.GBMS.BLL
{
    public class SystemControlBLL
    {
        IDBManager dbManager = new DBManager(SystemInfo._DataProvider, SystemInfo._ConnectionString);
        public DataTable BudgetYear()
        {
            try
            {
                dbManager.CreateParameters(1);
                dbManager.AddParameters(0, "@bgm_sys_control_name", "bg_year");
                string sql = " select bgm_sys_control_values "
                           + " from bgm_system_control"
                           + " where bgm_sys_control_name=@bgm_sys_control_name";
                DataTable dt = new DataTable();
                dbManager.Open();
                dt = dbManager.ExecuteDataSet(CommandType.Text, sql).Tables[0];
                return dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dbManager.Dispose();
            }
        }

        public string JobSiteStrategyID()
        {
            try
            {
                string strResult = "";
                dbManager.CreateParameters(1);
                dbManager.AddParameters(0, "@bgm_sys_control_name", "job_site_strategy");
                string sql = " select bgm_sys_control_values "
                           + " from bgm_system_control"
                           + " where bgm_sys_control_name=@bgm_sys_control_name";
                DataTable dt = new DataTable();
                dbManager.Open();
                dt = dbManager.ExecuteDataSet(CommandType.Text, sql).Tables[0];

                if (dt.Rows.Count > 0)
                {
                    strResult = dt.Rows[0][0].ToString();
                }

                return strResult;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dbManager.Dispose();
            }
        }

        public string JobSiteFinanceID()
        {
            try
            {
                string strResult = "";
                dbManager.CreateParameters(1);
                dbManager.AddParameters(0, "@bgm_sys_control_name", "job_site_finance");
                string sql = " select bgm_sys_control_values "
                           + " from bgm_system_control"
                           + " where bgm_sys_control_name=@bgm_sys_control_name";
                DataTable dt = new DataTable();
                dbManager.Open();
                dt = dbManager.ExecuteDataSet(CommandType.Text, sql).Tables[0];

                if (dt.Rows.Count > 0)
                {
                    strResult = dt.Rows[0][0].ToString();
                }

                return strResult;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dbManager.Dispose();
            }
        }

        public string JobSiteOption(string strOptionSeq)
        {
            try
            {
                string strResult = "";
                dbManager.CreateParameters(1);
                dbManager.AddParameters(0, "@bgm_sys_control_name", "job_site_option" + strOptionSeq);
                string sql = " select bgm_sys_control_values "
                           + " from bgm_system_control"
                           + " where bgm_sys_control_name = @bgm_sys_control_name";
                DataTable dt = new DataTable();
                dbManager.Open();
                dt = dbManager.ExecuteDataSet(CommandType.Text, sql).Tables[0];

                if (dt.Rows.Count > 0)
                {
                    strResult = dt.Rows[0][0].ToString();
                }

                return strResult;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dbManager.Dispose();
            }
        }

        public string GetSystemName()
        {
            try
            {
                string strResult = "";
                string sql = " select system_name"
                           + " from sys_system_controls";
                DataTable dt = new DataTable();
                dbManager.Open();
                dt = dbManager.ExecuteDataSet(CommandType.Text, sql).Tables[0];

                if (dt.Rows.Count > 0)
                {
                    strResult = dt.Rows[0][0].ToString();
                }

                return strResult;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dbManager.Dispose();
            }
        }
    }
}
